require('dotenv').config()
const { GraphQLServer } = require('graphql-yoga')
const { Prisma } = require('prisma-binding')
const resolvers = require('./resolvers')

const db = new Prisma({
  typeDefs: 'src/generated/prisma.graphql',
  endpoint: process.env.PRISMA_ENDPOINT,
  secret: process.env.PRISMA_SECRET,
  debug: true,
})

const server = new GraphQLServer({
  typeDefs: 'src/schema/index.graphql',
  resolvers,
  context: req => ({ ...req, db }),
})

server.start(({ port }) =>
  console.log(`Server is running on http://localhost:${port}`),
)
